home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / FromTheMag / JW FLV MEDIA PLAYER 4.2 / mediaplayer.exe / player.swf / scripts / com / jeroenwijering / parsers / ObjectParser.as < prev    next >
Text File  |  2008-11-04  |  4KB  |  148 lines

  1. package com.jeroenwijering.parsers
  2. {
  3.    import com.jeroenwijering.utils.Strings;
  4.    
  5.    public class ObjectParser
  6.    {
  7.       
  8.       protected static var EXTENSIONS:Object = {
  9.          "3g2":"video",
  10.          "3gp":"video",
  11.          "aac":"video",
  12.          "f4b":"video",
  13.          "f4p":"video",
  14.          "f4v":"video",
  15.          "flv":"video",
  16.          "gif":"image",
  17.          "jpg":"image",
  18.          "m4a":"video",
  19.          "m4v":"video",
  20.          "mov":"video",
  21.          "mp3":"sound",
  22.          "mp4":"video",
  23.          "png":"image",
  24.          "rbs":"sound",
  25.          "sdp":"video",
  26.          "swf":"image",
  27.          "vp6":"video"
  28.       };
  29.       
  30.       protected static var MIMETYPES:Object = {
  31.          "application/x-fcs":"rtmp",
  32.          "application/x-shockwave-flash":"image",
  33.          "audio/aac":"video",
  34.          "audio/m4a":"video",
  35.          "audio/mp4":"video",
  36.          "audio/mp3":"sound",
  37.          "audio/mpeg":"sound",
  38.          "audio/x-3gpp":"video",
  39.          "audio/x-m4a":"video",
  40.          "image/gif":"image",
  41.          "image/jpeg":"image",
  42.          "image/jpg":"image",
  43.          "image/png":"image",
  44.          "video/flv":"video",
  45.          "video/3gpp":"video",
  46.          "video/h264":"video",
  47.          "video/mp4":"video",
  48.          "video/x-3gpp":"video",
  49.          "video/x-flv":"video",
  50.          "video/x-m4v":"video",
  51.          "video/x-mp4":"video"
  52.       };
  53.       
  54.       protected static var ELEMENTS:Object = {
  55.          "author":undefined,
  56.          "date":undefined,
  57.          "description":undefined,
  58.          "duration":0,
  59.          "file":undefined,
  60.          "image":undefined,
  61.          "link":undefined,
  62.          "title":undefined,
  63.          "start":0,
  64.          "tags":undefined,
  65.          "type":undefined
  66.       };
  67.       
  68.       protected static var TYPES:Object = {
  69.          "camera":"",
  70.          "image":"",
  71.          "rtmp":"",
  72.          "sound":"",
  73.          "video":"",
  74.          "youtube":""
  75.       };
  76.        
  77.       
  78.       public function ObjectParser()
  79.       {
  80.          super();
  81.       }
  82.       
  83.       public static function complete(param1:Object) : Object
  84.       {
  85.          var _loc2_:* = null;
  86.          if(param1["type"])
  87.          {
  88.             param1["type"] = param1["type"].toLowerCase();
  89.          }
  90.          if(param1["file"] == undefined)
  91.          {
  92.             delete param1["type"];
  93.          }
  94.          else if(ObjectParser.TYPES[param1["type"]] == undefined)
  95.          {
  96.             if(ObjectParser.EXTENSIONS[param1["type"]] != undefined)
  97.             {
  98.                param1["type"] = ObjectParser.EXTENSIONS[param1["type"]];
  99.             }
  100.             else if(param1["file"].indexOf("youtube.com/watch") > -1 || param1["file"].indexOf("youtube.com/v/") > -1)
  101.             {
  102.                param1["type"] = "youtube";
  103.             }
  104.             else if(ObjectParser.MIMETYPES[param1["type"]] != undefined)
  105.             {
  106.                param1["type"] = ObjectParser.MIMETYPES[param1["type"]];
  107.             }
  108.             else
  109.             {
  110.                param1["type"] = undefined;
  111.                for(_loc2_ in ObjectParser.EXTENSIONS)
  112.                {
  113.                   if(param1["file"] && param1["file"].substr(-3).toLowerCase() == _loc2_)
  114.                   {
  115.                      param1["type"] = ObjectParser.EXTENSIONS[_loc2_];
  116.                      break;
  117.                   }
  118.                }
  119.             }
  120.          }
  121.          if(!param1["duration"])
  122.          {
  123.             param1["duration"] = 0;
  124.          }
  125.          if(!param1["start"])
  126.          {
  127.             param1["start"] = 0;
  128.          }
  129.          return param1;
  130.       }
  131.       
  132.       public static function parse(param1:Object) : Object
  133.       {
  134.          var _loc2_:* = undefined;
  135.          var _loc3_:* = null;
  136.          _loc2_ = new Object();
  137.          for(_loc3_ in ObjectParser.ELEMENTS)
  138.          {
  139.             if(param1[_loc3_] != undefined)
  140.             {
  141.                _loc2_[_loc3_] = Strings.serialize(param1[_loc3_]);
  142.             }
  143.          }
  144.          return ObjectParser.complete(_loc2_);
  145.       }
  146.    }
  147. }
  148.